package com.bjpower.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjpower.convent.UserPayConfigVoConvent;
import com.bjpower.domain.UserPayConfig;
import com.bjpower.models.Result;
import com.bjpower.models.request.CreatePayWayConfigRequest;
import com.bjpower.models.request.UserPageInfoRequest;
import com.bjpower.models.vo.UserPayConfigVo;
import com.bjpower.services.PayConfigListService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
public class PayConfigController {

    @Resource
    private PayConfigListService payConfigService;

    @Resource
    private UserPayConfigVoConvent userPayConfigVoConvent;

    @GetMapping("/product/payConfig")
    public Result getPayConfig(@Validated UserPageInfoRequest pageInfoRequest){
        IPage<UserPayConfig> payConfigList = payConfigService.getPayConfigList(pageInfoRequest);
        List<UserPayConfig> records = payConfigList.getRecords();
        long pages = payConfigList.getPages();
        long current = payConfigList.getCurrent();
        //创建vo对象
        List<UserPayConfigVo> list = userPayConfigVoConvent.convertListUserPayConfigVo(records);
        HashMap<String, Object> data = new HashMap<>();
        data.put("list", list);
        data.put("pages", pages);
        data.put("current", current);
        return Result.ok(data);
    }
    /**
     * 创建商户支付配置
     */
    @PostMapping("/payConfig/create")
    public Result createPayConfig(@Validated @RequestBody CreatePayWayConfigRequest configRequest){
        payConfigService.createPayConfig(configRequest);
        return Result.ok();
    }

}
